package com.wanxi.controller;

import com.wanxi.VO.ContactVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * 联系我们
 * @Author : 林子淳
 * @create 2023/3/11 9:31
 */
@RestController
public class ContactController {
    @Autowired
    private ContactService contactService;

    @PostMapping("/back/contact/add")
    @CrossOrigin
    protected ResultDTO add(ContactVO contactVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = contactService.add(contactVO);
        return resultDTO;
    }
    @PostMapping("/back/contact/delete")
    @CrossOrigin
    protected ResultDTO delete(ContactVO contactVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = contactService.delete(contactVO);
        return resultDTO;
    }
    @GetMapping("/back/contact/findAll")
    @CrossOrigin
    protected ResultDTO findAll(ContactVO contactVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = contactService.findAll(contactVO);
        return resultDTO;
    }
    @GetMapping("/back/contact/findById")
    @CrossOrigin
    protected ResultDTO findById(ContactVO contactVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = contactService.findById(contactVO);
        return resultDTO;
    }
    @PostMapping("/back/contact/update")
    @CrossOrigin
    protected ResultDTO update(ContactVO contactVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = contactService.update(contactVO);
        return resultDTO;
    }

}
